
 // const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin')
 const { ModuleFederationPlugin } = require('webpack').container
 const promiseTransfer = require('./promiseTransfer')
 //console.log(promiseTransfer('lib_app@http://localhost:3000/remoteEntry.js'), 9999)
 const path = require('path');
 const dependencies = require('../package.json').dependencies
 export function chainWebpack(config, { env, webpack, createCSSRule }) {
  config.resolve.modules.add(path.resolve(__dirname, 'src'))

  config.plugin('moduleFederation').use(ModuleFederationPlugin, [
    {
      name: 'app1',
      library: { type: 'var', name: 'app1' },
      filename: 'app1.js',
      exposes: {
          './Demo': './src/components/Demo.tsx'
      },
      remotes: {
        'app_cdn': promiseTransfer('app_cdn@http://localhost:5001/remoteEntry.js'),
      },
      // shared: {
      //   react: {
      //     singleton: true,
      //     eager: true,
      //     requiredVersion: dependencies.react,
      //   },
      //   'react-dom': {
      //     singleton: true,
      //     eager: true,
      //     requiredVersion: dependencies['react-dom'],
      //   }
      // }
    },
  ])

  // 这里避免模块查找不存在
  // config.merge({
  //   resolve: {
  //       alias: {
  //         'app_cdn': '/',
  //       },
  //     },
  // })
 
 }
